#pragma once
#include <fstream>
#include "util.h"
/**
* Provides the basic infrastructure for reading binary 
* files.
* @author Koen Samyn
*/
class BinaryReader
{
public:
	/**
	* Creates an empty BinaryReader object.
	*/ 
	BinaryReader();
	/**
	* Creates a BinaryReader object for the specified file.
	* @param filename the file to read.
	*/
	BinaryReader(tstring filename);
	/**
	* Destroys the BinaryReader object.
	*/
	virtual ~BinaryReader(void);
	/**
	* Sets the file to read.
	* @param filename the file to read.
	*/
	void SetFileName(tstring filename){
		m_FileName = filename;
	}
	/**
	* Opens the file for reading.
	* @return true if opening the file was succesful.
	*/
	bool Open();
	/**
	* Closes the file.
	*/
	void Close();
	/**
	* Read a string and return it as a tstring.
	* @return the tstring
	*/
	tstring ReadString();
	/**
	* Read one byte as an integer.
	*/ 
	int ReadByte();
	/**
	* Reads an integer encoded with Little Endian.
	*/
	int ReadLittleInt();
	/**
	*  Reads an integer encoded with BigEndian.
	*/
	int ReadBigInt();
	/**
	* Reads a short encoded with Little Endian.
	*/
	short ReadLittleShort();
	/**
	* Reads an unsigned short encoded with Little Endian.
	* @return the unsigned short.
	*/
	unsigned short ReadLittleUShort();
	/**
	* Reads a float encoded with Little Endian.
	*/
	float ReadLittleFloat();
	/**
	* Reads a double encoded with BigEndian.
	*/
	double ReadLittleDouble();
	/**
	* Read a string terminated by zero.
	*/
	tstring ReadAsciiString();
	/**
	* Skip the number of bytes in the file.
	* @param nrOfBytes the number of bytes to skip.
	*/
	void Skip(int nrOfBytes);

protected:
	/**
	* The input file stream object.
	*/
	ifstream m_File;
	/**
	* The file to read.
	*/
	tstring m_FileName;
	/**
	* If true, opening the file was succesful, if false
	* the file is still closed, or opening the file was unsuccesful.
	*/
	bool m_Open;
private:
	// -------------------------
	// Disabling default copy constructor and default assignment operator.
	// If you get a linker error from one of these functions, your class is internally trying to use them. This is
	// an error in your class, these declarations are deliberately made without implementation because they should never be used.
	// -------------------------

	BinaryReader(const BinaryReader& t);
	BinaryReader& operator=(const BinaryReader& t);
};
